//
//  HTButtonCell.m
//  TruckUser
//
//  Created by Ting Han on 2017/11/2.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "HTButtonCell.h"

@interface HTButtonCell()

@end

@implementation HTButtonCell
- (void)setTitleStr:(NSString *)titleStr{
    [self.mainButton setTitle:titleStr forState:UIControlStateNormal];
    [self setNeedsLayout];
    [self layoutIfNeeded];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    self.mainButton.contentEdgeInsets = UIEdgeInsetsMake(4, 8, 4, 8);
}
- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    UICollectionViewLayoutAttributes *attributes = [super preferredLayoutAttributesFittingAttributes:layoutAttributes];
    
    CGRect frame = [self.mainButton.titleLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, self.mainButton.titleLabel.frame.size.height) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.mainButton.titleLabel.font,NSFontAttributeName, nil] context:nil];
    
    frame.size.height = self.mainButton.titleLabel.frame.size.height + 16;
    frame.size.width = frame.size.width + 24;
    attributes.frame = frame;
    return attributes;
}
@end
